package com.neusoft.lohas.modules.ivm.entity.merchant;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.neusoft.lohas.common.persistence.IdEntity;
import com.neusoft.lohas.modules.ivm.entity.order.Order;

/**
 * 送货员Entity
 * @author Jackie.Liu
 * @version 2014-11-03
 */
@Entity
@Table(name = "ivm_delivery_indent")
@DynamicInsert @DynamicUpdate
public class DeliveryIndent  extends IdEntity<DeliveryIndent>{
	
	private static final long serialVersionUID = 1L;
	private Merchant merchant; //商户信息
	private Order order;	//对应送货订单Id
	private DeliveryMember deliveryMember; //送货员信息
	private Date deliveryDate; //送货时间
	
	public DeliveryIndent() {
		super();
	}

	public DeliveryIndent(String id){
		this();
		this.id = id;
	}
	
	@ManyToOne
	@JoinColumn(name="merchant_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@JsonIgnore
	@NotNull(message="所属商户信息不能为空")
	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}
	
	@OneToOne(cascade = { CascadeType.REFRESH, CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.EAGER, optional = false)
	@JoinColumn(name = "order_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@JsonIgnore
	@NotNull(message="所属订单信息不能为空")
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@ManyToOne
	@JoinColumn(name="member_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@JsonIgnore
	@NotNull(message="所属送货员信息不能为空")
	public DeliveryMember getDeliveryMember() {
		return deliveryMember;
	}
	
	public void setDeliveryMember(DeliveryMember deliveryMember) {
		this.deliveryMember = deliveryMember;
	}

	public Date getDeliveryDate() {
		return deliveryDate;
	}

	public void setDeliveryDate(Date deliveryDate) {
		//格式化部分
		this.deliveryDate = deliveryDate;
	}
	
}
